// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package parts

import (
	"github.com/wrzfeijianshen/gxui/gxui/gxuiwidgets"
	"github.com/wrzfeijianshen/gxui/gxui/gxuicore/math"
	"github.com/wrzfeijianshen/gxui/gxui/gxuigui/mixins/outer"
)

type BackgroundBorderPainterOuter interface {
	outer.Redrawer
}

type BackgroundBorderPainter struct {
	outer BackgroundBorderPainterOuter
	brush gxuiwidgets.Brush
	pen   gxuiwidgets.Pen
}

func (b *BackgroundBorderPainter) Init(outer BackgroundBorderPainterOuter) {
	b.outer = outer
	b.brush = gxuiwidgets.DefaultBrush
	b.pen = gxuiwidgets.DefaultPen
}

func (b *BackgroundBorderPainter) PaintBackground(c gxuiwidgets.Canvas, r math.Rect) {
	if b.brush.Color.A != 0 {
		w := b.pen.Width
		c.DrawRoundedRect(r, w, w, w, w, gxuiwidgets.TransparentPen, b.brush)
	}
}

func (b *BackgroundBorderPainter) PaintBorder(c gxuiwidgets.Canvas, r math.Rect) {
	if b.pen.Color.A != 0 && b.pen.Width != 0 {
		w := b.pen.Width
		c.DrawRoundedRect(r, w, w, w, w, b.pen, gxuiwidgets.TransparentBrush)
	}
}

func (b *BackgroundBorderPainter) BackgroundBrush() gxuiwidgets.Brush {
	return b.brush
}

func (b *BackgroundBorderPainter) SetBackgroundBrush(brush gxuiwidgets.Brush) {
	if b.brush != brush {
		b.brush = brush
		b.outer.Redraw()
	}
}

func (b *BackgroundBorderPainter) BorderPen() gxuiwidgets.Pen {
	return b.pen
}

func (b *BackgroundBorderPainter) SetBorderPen(pen gxuiwidgets.Pen) {
	if b.pen != pen {
		b.pen = pen
		b.outer.Redraw()
	}
}
